var processing = false;
var flag=false;
//var mPhone=""+GetQueryString("mPhone");
$(function(){
	//验证身份
	$("#daojishi").click(function(){
			var mPhone=$("#mPhone").val();
			if(mPhone==null || mPhone==""){
				var message = "手机号码不能为空！！！";
				addStyle(message);
				return false;
			}
			if(mPhone.length!=11) { 
	           var message = "请输入有效的11 位手机号码！！";
				addStyle(message);
				return false;
			} 
			var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0]{9})|(18[0-9]{1}))+\d{8})$/; 
			if (!myreg.test(mPhone)) { 
				var message = "手机号码格式不正确!!!";
				addStyle(message);
				return false;
			}
			//发送验证码
			$.ajax({
				type:"post",
				url:rootPath+"/captcha/getCaptcha",
				data:{'mPhone':mPhone,'mStyle':1},
				//dataType:"json",
				success:function(data){
					if(data.resultSuccess){
						$("#msg").text("");
						flag=true;
					}else{
						$("#msg").text(data.resultDesc)
						$("#msg").css("font-size","28px")
						.css("text-align","center")
						.css("margin-top","66px")
						.css("margin-bottom","-50px")
						.css("color","red");
					}
				}
			});
			var i = 60;
	        if (processing) return ;
	        time($("#daojishi"));
			if(i!=0) {
				return false;
			}else{
				return true;
			};
			function time(o) {
				  if (i == 0) {
				 	 o.removeAttr("disabled");
				     processing = false;   
				     o.html("获取验证码"); 
				     wait = 30;
				  } else {
				     o.attr("disabled",true); 
				     o.html("重新发送(" + i + ")");
				     i--;
				     processing = true;
				     setTimeout(function(){ 
				       time(o)
				     },1000)               
				  }
				}
	});

	$("#confirm").click(function(){
		/**校验用户**************/
		var mPhone = $("#mPhone").val();
		var registerCode = $("#registerCode").val();
		if(mPhone==null || mPhone==""){
			var message = "手机号码不能为空！！！";
			addStyle(message);
			return false;
		}
		if(registerCode==null || registerCode==""){
			var message = "验证码不能为空！！！";
			addStyle(message);
			return false;
		}
		if(mPhone.length!=11) { 
           var message = "请输入有效的11 位手机号码！！";
			addStyle(message);
			return false;
		} 
		var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0]{9})|(18[0-9]{1}))+\d{8})$/; 
		if (!myreg.test(mPhone)) { 
			var message = "手机号码格式不正确!!!";
			addStyle(message);
			return false;
		}
		var data = $("form").serialize();
		$.ajax({
			type:"post",
			url:rootPath+"/member/register",
			data:data,
			//dataType:"json",
			success:function(data){
				if(data.resultSuccess){
					//alert(data.resultDesc)
					$("#msg").text("");
					window.location.href=rootPath+"/register/registerBetween?mPhone="+data.mPhone;
				}else{
					$("#msg").text(data.resultDesc)
					$("#msg").css("font-size","28px")
					.css("text-align","center")
					.css("margin-top","66px")
					.css("margin-bottom","-50px")
					.css("color","red");
				}
			}
		})
	});
	
	/**添加样式**/
	function addStyle(datas){
		$("#msg").text(datas)
		$("#msg").css("font-size","28px")
		.css("text-align","center")
		.css("margin-top","66px")
		.css("margin-bottom","-50px")
		.css("color","red");
	}
	
	
	
});